<?php
declare (strict_types=1);

namespace app\course\model\base;

use app\common\model\BaseModel;
use think\model\relation\BelongsTo;

/**
 * 学习班模型
 */
class StudyClass extends BaseModel
{
    /**
     * 表名
     *
     * @var string
     */
    protected $name = 'course_study_class';

    /**
     * 设置自动写入时间
     *
     * @var boolean
     */
    protected $autoWriteTimestamp = true;

    /**
     * 不需要更新时间
     *
     * @var boolean
     */
    protected $updateTime = false;

    /**
     * 定义字段类型
     *
     * @var array
     */
    protected $type = [
        'signin_start_time'   => 'int',
        'signin_end_time'     => 'int',
        'training_start_time' => 'int',
        'training_end_time'   => 'int',
        'create_time'         => 'int',
    ];

    /**
     * 课程名称
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/05/10
     */
    public function courseTitle(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id')->bind(['course_title' => 'title']);
    }

    /**
     * 课程名称
     * Author: 亓官雨树 <lucky.max@foxmail.com>
     * Date: 22/05/10
     */
    public function courseTitleCover(): BelongsTo
    {
        return $this->belongsTo(Course::class, 'course_id')->with(['cover_url'])->field('id,cover,title');//->bind(['course_title' => 'title', 'cover_url']);
    }
}
